package com.kone.robot;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.collections.map.LinkedMap;

public class ImageClient {
	public int depth = 3;
	public static int stat = 1;
	public List<String> images = new ArrayList<String>();
	public Map<Integer, LinkedList<U>> urlFetch = new HashMap<Integer, LinkedList<U>>();
	public LinkedList<U> allUrls = new LinkedList<U>();
	public List<U> urlFetched = new ArrayList<U>();
	public LinkedMap webFetch = new LinkedMap();
	public List<String> webFetched = new ArrayList<String>();
	public Map<String, String> webs = new HashMap<String, String>();
	public final static String USER_AGENT_H = "User-Agent";
	public final static String REFERER_H = "Referer";
	public final static String USER_AGENT = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22";
	public final static String EXT = "png";
	public static FileWriter writer;
	public static String path = "E://image";
	public boolean stop = false;

	public static File FILE = new File("d://consolo.txt");

	public ImageClient(String url, int depth, String path) {
		try {
			writer = new FileWriter(new File("E://xxxx.txt"));
			init(url, depth);
			this.path = path;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void init(String url, int depth) {
		this.depth(depth);
		LinkedList<U> m = (LinkedList<U>) urlFetch.get(0);
		U uu = new U(0, url);
		m.add(uu);
		allUrls.add(uu);
	}

	public void depth(int depth) {
		for (int i = 0; i <= depth; i++) {
			urlFetch.put(i, new LinkedList<U>());
		}
		this.depth = depth;
	}

	public List<String> images() {
		return images;
	}

	public static void main(String[] args) {
		try {
			ExecutorService pool = Executors.newFixedThreadPool(4);
			AchorFetch a = new AchorFetch("http://121.199.47.8/", 5);
			new Thread(a).start();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
